public class WaterV {
    public int water(int[] elem){
        int right = elem.length - 1;
        int left = 0;
        int v = 0;
        while (left < right){
            int newV = Math.min(elem[right],elem[left]) * (right - left);
            v = Math.max(v,newV);
            if (elem[left] < elem[right]){
                left++;
            }else {
                right--;
            }
        }
        return v;
    }
}
